package com.ddxz.tool.sql.struct;

import com.ddxz.tool.sql.exception.DdxzSqlEnumException;
import lombok.Getter;

import static com.ddxz.tool.sql.exception.SqlErrorStatus.INVALID_ENUM_CODE;

/**
 * enum description
 *
 * @author 朱宗刚
 * @version 1.0.0
 * @date 2020/8/21
 */

@Getter
public enum DdxzAndOrType {
    /**
     * 数据库多条件拼接方式
     */
    AND(1, " AND "),
    OR(2, " OR ");

    private int code;

    private String value;

    DdxzAndOrType(int code, String value) {
        this.code = code;
        this.value = value;
    }

    public static DdxzAndOrType getTypeByCode(int code) {
        for(DdxzAndOrType type : values()) {
            if(type.getCode() == code) {
                return type;
            }
        }

        throw new DdxzSqlEnumException(INVALID_ENUM_CODE, code, 1, values().length);
    }
}
